import request from "@/utils/request";

const state = {
  talentPoolTempId: "",
  isCancel: null,
  adminUsers: [],
  positionTypes: []
};

const mutations = {
  talentPoolTempId(state, payload) {
    state.talentPoolTempId = payload;
  },
  isCancel(state, payload) {
    state.isCancel = payload;
  },
  updatePostionTypes(state, payload) {
    state.positionTypes = payload;
  },
  updateAdminUsers(state, payload) {
    state.adminUsers = payload;
  }
};

const actions = {
  loadPositionTypeAct({ commit }) {
    request({
      url: `/recruit2/api/v1/positionTypes/selectPositionType`,
      method: "GET"
    })
      .then((res) => {
        commit("updatePostionTypes", res.data);
      })
      .catch((err) => {
        console.log("loadPositionTypeAct", err);
      });
  },
  loadAdminUsersAct({ commit }) {
    request({
      url: `/hr/api/v1/users/listUserHasRoleInSite`,
      method: "get"
    })
      .then((res) => {
        commit(
          "updateAdminUsers",
          res.data.map((item) => ({
            label: item.name,
            value: item.id,
            phone: item.phone
          }))
        );
      })
      .catch((err) => {
        console.log("loadAdminUsersAct", err);
      });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
